public class Bubble {
  private float bDiameter;
  private color bColor;

  private PVector bPosition;
  private float bVelocity;

  private float finalPosition;
  private boolean hideBubble;

  public Bubble() {
    float r, g, b;
    r = random(0, 255);
    g = random(0, 255);
    b = random(0, 255);

    bColor = color(r, g, b);

    bPosition = new PVector( random(0, width), (height * 1.1) );

    bDiameter = random(50, 400);
    bVelocity = random( 1, 4 );

    finalPosition = -500;
    hideBubble = false;
  }

  public void draw() {
    if ( !hideBubble ) {
      moveBubble();
      
      stroke( 255 );
      strokeWeight( 3 );

      fill( bColor, 192);

      ellipse( bPosition.x, bPosition.y, bDiameter/2, bDiameter/2 );
    }
  }

  private void moveBubble() {
    PVector posFinal = new PVector( random (0, width), finalPosition );
    PVector desiredPosition = PVector.sub(posFinal, bPosition);

    desiredPosition.normalize();
    desiredPosition.mult(bVelocity);

    bPosition.add( desiredPosition );
  }

  public void blowBubble(float x, float y) {
    PVector pV = new PVector(x, y);
    float distClick = bPosition.dist(pV);

    if ( distClick < (bDiameter/2) ) {
      hideBubble = true;
    }
  }
}

